package com.car.controller.user;

import com.car.entity.User;
import com.car.service.custormer.UserLoginService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 贾勇
 * @ClassName UserLoginController
 * @Description: 用户登录
 * @DateTime: 2021-12-02 14:22
 */
@RestController
public class UserLoginController {

    @Getter
    @Setter
    @Autowired
    private UserLoginService userLoginService;

    @RequestMapping("/toLogin")
    public ModelAndView toLogin(){
        return new ModelAndView("/login");
    }

    @RequestMapping("/toWelcome")
    public ModelAndView toWelcome(){
        return new ModelAndView("/welcome");
    }



    @RequestMapping("/login")
    public ModelAndView login(User user, HttpSession session) {

        ModelAndView mv = new ModelAndView();
        User u = userLoginService.userLogin(user);
        mv.addObject("u", u);
        if(session.getAttribute("use") == null){
            session.setAttribute("use",u);
        }else {
            session.setAttribute("use",u);
        }
        mv.setViewName("home");
        return mv;
    }


}
